﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using NekoVampire.TwitterClient.Configuration;

namespace NekoVampire.TwitterClient.Forms
{
    public partial class Setting : Form
    {
        private UserConfiguration config;

        public Setting(UserConfiguration configuration)
        {
            this.config = configuration;

            InitializeComponent();
        }

        private void Setting_Load(object sender, EventArgs e)
        {
            userIdBox.Text = config.userId;
            passwordBox.Text = config.password;
            AddStatus.Checked = config.addStatus;

            unreadLabel.Font = config.unreadFont;
            unreadLabel.Text = config.unreadFont.ToString();
            readLabel.Font = config.readFont;
            readLabel.Text = config.readFont.ToString();

            getTimeLineNumeric.Value = config.getTimeLineCount;
            startupTimeLineNumeric.Value = config.startupTimeLineCount;

            allRepliesCheckBox.Checked = config.allReplies;
            myStatusInRepliesCheckBox.Checked = config.myStatusInReplies;
            getOldStatusCheckBox.Checked = config.getOldStatus;
            
            colorLabel.ForeColor = config.ForeColor;
            colorLabel.BackColor = config.BackColor;
            colorLabel.Text = "[前景:" + colorLabel.ForeColor.ToString() + "] [背景:" + colorLabel.BackColor.ToString() + "]";

            viewUnfollowCheckBox.Checked = config.ViewUnfollow;
            unfollowColorLabel.ForeColor = config.UnfollowColor;
            unfollowColorLabel.BackColor = config.BackColor;
            unfollowColorLabel.Text = unfollowColorLabel.ForeColor.ToString();

            timerNumericUpDown.Value = config.Timer;
        }

        private void okButton_Click(object sender, EventArgs e)
        {
            applyButton_Click(sender, e);
            this.Close();
            return;
        }

        private void cancelButton_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void applyButton_Click(object sender, EventArgs e)
        {
            config.userId = userIdBox.Text;
            config.password = passwordBox.Text;
            config.addStatus = AddStatus.Checked;
            config.unreadFont = unreadLabel.Font;
            config.readFont = readLabel.Font;
            config.getTimeLineCount = (int)getTimeLineNumeric.Value;
            config.startupTimeLineCount = (int)startupTimeLineNumeric.Value;
            config.allReplies = allRepliesCheckBox.Checked;
            config.myStatusInReplies = myStatusInRepliesCheckBox.Checked;
            config.getOldStatus = getOldStatusCheckBox.Checked;
            config.ForeColor = colorLabel.ForeColor;
            config.BackColor = colorLabel.BackColor;
            config.ViewUnfollow = viewUnfollowCheckBox.Checked;
            config.UnfollowColor = unfollowColorLabel.ForeColor;
            config.Timer = (int)timerNumericUpDown.Value;

            config.Save();
        }

        private void unreadButton_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = unreadLabel.Font;
            fontDialog1.ShowDialog();
            unreadLabel.Font = fontDialog1.Font;
            unreadLabel.Text = unreadLabel.Font.ToString();
        }

        private void readButton_Click(object sender, EventArgs e)
        {
            fontDialog1.Font = readLabel.Font;
            fontDialog1.ShowDialog();
            readLabel.Font = fontDialog1.Font;
            readLabel.Text = readLabel.Font.ToString();
        }

        private void foreColorButton_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = colorLabel.ForeColor;
            colorDialog1.ShowDialog();
            colorLabel.ForeColor = colorDialog1.Color;
            colorLabel.Text = "[前景:" + colorLabel.ForeColor.ToString() + "] [背景:" + colorLabel.BackColor.ToString() + "]";
        }

        private void backColorButton_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = colorLabel.BackColor;
            colorDialog1.ShowDialog();
            colorLabel.BackColor = colorDialog1.Color;
            colorLabel.Text = "[前景:" + colorLabel.ForeColor.ToString() + "] [背景:" + colorLabel.BackColor.ToString() + "]";
        }

        private void unfollowColorButton_Click(object sender, EventArgs e)
        {
            colorDialog1.Color = unfollowColorLabel.ForeColor;
            colorDialog1.ShowDialog();
            unfollowColorLabel.ForeColor = colorDialog1.Color;
            unfollowColorLabel.Text = unfollowColorLabel.ForeColor.ToString();
        }
    }
}
